﻿
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Text;

namespace SharpSoft.Web.Extensions
{
    public static class HostExtensions
    {

        /// <summary>
        /// 获取相对于wwwroot的绝对路径
        /// </summary>
        /// <param name="paths"></param>
        /// <returns></returns>
        public static string MapPath(this IWebHostEnvironment hostingEnvironment, params string[] paths)
        {
            List<string> l = new List<string>(paths.Length + 1);
            l.Add(hostingEnvironment.WebRootPath); 
            l.AddRange(paths);
            return System.IO.Path.Combine(l.ToArray());
        }
        /// <summary>
        /// 获取相对于app根目录的绝对路径
        /// </summary>
        /// <param name="paths"></param>
        /// <returns></returns>
        public static string MapAppPath(this IWebHostEnvironment hostingEnvironment, params string[] paths)
        {
            List<string> l = new List<string>(paths.Length + 1);
            l.Add(hostingEnvironment.ContentRootPath);
            l.AddRange(paths);
            return System.IO.Path.Combine(l.ToArray());
        }
    }
}
